/**
 * 
 */
package com.yidin.entry;

import java.util.List;

import com.yidin.lsc.MyBaseAdapter;
import com.yidin.lsc.PhotoListParcelable;
import com.yidin.lsc.R;
import com.yidin.util.NetImageBase;
import com.yidin.util.imageCallback;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Gallery;
import android.widget.ImageView;

/**
 * 我的相片的九宫格相册适配器
 * 
 * @author cola
 * 
 */
public class MyPhotoDetailAdapter extends MyBaseAdapter {
	private Context mContext;
	private List<PhotoListParcelable> filterArray;

	public MyPhotoDetailAdapter(List<PhotoListParcelable> info, Context mContext) {
		super(info, mContext);
		filterArray = info;
		this.mContext = mContext;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return filterArray.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return filterArray.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View view = convertView;
		final int i = position;
		ViewHolder holder = null;
		if (view == null) {
			holder = new ViewHolder();
			int width = 450;// bmImg.getWidth();
			int height = 250;// bmImg.getHeight();
			ImageView imageview = new ImageView(mContext);
			holder.icon = imageview;
			view = imageview;
			final ImageView iv = holder.icon;
			view.setTag(holder);
			Bitmap bm = null;
			if (this.filterArray.get(position).FilePath != null) {// 请求图标
				bm = new NetImageBase().getLogoBitmap(handler, context,
						this.filterArray.get(position).FilePath,
						new imageCallback() {
							public void getImage(Bitmap bm) {
								// TODO Auto-generated method stub
								if (bm != null) {
									iv.setImageBitmap(bm);
									getIsSelected().put(i, bm);
								}
							}
						});

			}
			if (bm != null) {
				bm = new NetImageBase().getLocalBitmap(null, context, this.filterArray.get(position).FilePath, 450, 170);
				iv.setImageBitmap(bm);
				getIsSelected().put(i, bm);
			}
//			imageview.setImageBitmap(BitmapFactory.decodeResource(
//					mContext.getResources(), R.drawable.photo));
			imageview.setLayoutParams(new Gallery.LayoutParams(width, height));
			imageview.setScaleType(ImageView.ScaleType.FIT_CENTER);// 设置显示比例类型
			
		}else
			if (getIsSelected().get(position) != null)
				holder.icon.setImageBitmap(getIsSelected().get(position));
		return view;
	}

	class ViewHolder {
		ImageView icon;
	}
	
	/**
	 * 用于图片滑动时改变图片其它的信息
	 * @param p
	 */
	public interface photoChange{
		public void changePosition(int p);
	}
	
	private photoChange p;
	public void setOnChangeListener(photoChange p){
		this.p = p;
	}
}
